package com.wx.tgp.jfinal.demo.controller;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.wx.tgp.jfinal.demo.entity.User;
import com.wx.tgp.jfinal.demo.interceptor.AuthInterceptor;
import com.wx.tgp.jfinal.demo.service.UserService;
import com.wx.tgp.jfinal.demo.validator.LoginValidator;

import javax.jws.soap.SOAPBinding;

/**
 * Created by Administrator on 2016/5/6.
 */
public class UserController extends Controller {
    private UserService userService = new UserService();

    public void index(){

    }

    @Before(LoginValidator.class)
    public void login(){
        String username = getPara("username");
        String password = getPara("password");
        boolean logincheck = userService.login(username,password);
        if(logincheck){
            renderJson("10000");
            //getSession().setA("flag",true);
        }else{
            renderJson("10001");
        }
    }

    public void register(){
        String username = getPara("username");
        String password = getPara("password");
        boolean result = userService.add(username,password);
        if(result){
            renderJson("10010");
        }else{
            renderJson("10011");
        }
    }

    @Before(AuthInterceptor.class)
    public void show(){
        renderJsp("user.jsp");
    }

    public void image(){
        try{
            getFile(getPara("img"),"UTF-8");
            renderJson("20010");
        } catch (Exception e){
            renderJson("20012");
        }
    }
}
